﻿@model UserListModel
@using System.Globalization;
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <button class="layui-btn  layui-btn-normal layuiadmin-btn-tags" data-type="add">添加</button>
        </div>
        <div class="layui-card-body">
            <table id="LAY-topic-list" lay-filter="LAY-topic-list"></table>
            <script type="text/html" id="layuiadmin-app-cont-tagsbar">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script type="text/html" id="approvedTpl">
    <input type="checkbox" name="Approved" value="{{d.Id}}" title="已通过" lay-filter="approved" {{ d.Approved ? 'checked' : '' }}>
</script>
<script type="text/html" id="activeTpl">
    <input type="checkbox" name="Active" lay-skin="switch" value="{{d.Id}}" lay-filter="active" lay-text="激活|停用" {{ d.Active ? 'checked' : ''}}>
</script>
<script>

    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table'], function () {
        var index = layer.load(2, { shade: false });
        var table = layui.table
            , form = layui.form;
        //分类管理
        table.render({
            elem: '#LAY-topic-list'
            , url: '@Html.Raw(Url.Action("UserReviewList", "User"))' //模拟接口
            ,method:'post'
            , page: true //开启分页
            , even: true
            , limit: 15
            , limits: [15,30,50,100]
            , cols: [[
                { type: 'numbers', fixed: 'left' }
                , { field: 'Id', width: 100, title: 'ID' }
                , { field: 'Nickname', title: '昵称', minWidth: 100 }
                , { field: 'Phone', title: '电话', minWidth: 150 }
                , { field: 'InvitedCode', title: '邀请码', minWidth: 150 }
                , { field: 'UserRoleNames', title: '客户角色名称', minWidth: 150 }
                , { field: 'CreateTime', title: '创建日期', minWidth: 150, templet: '<div>{{ layui.util.timeAgo(d.CreateTime) }}</div>' }
                , { field: 'Approved', title: '是否批准', templet: '#approvedTpl', minWidth: 80, align: 'center' }
                , { field: 'Active', title: '是否激活', templet: '#activeTpl', minWidth: 80, align: 'center' }
                , { title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#layuiadmin-app-cont-tagsbar' }
            ]]
            , text: { none: '一条数据也没有^_^' }
            , done: function () {
                layer.close(index);
            }
        });

        //监听工具条
        table.on('tool(LAY-topic-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    obj.del();
                    $.post('@Url.Action("Delete")', { id: obj.data.Id });
                    layer.close(index);
                });

            }
        });
        //监听锁定操作
         form.on('switch(active)', function (obj) {
            var check = obj.elem.checked;
            $.post('@Url.Action("Active")', { Id: this.value, checked: check });
        })
        form.on('switch(approved)', function (obj) {
            var check = obj.elem.checked;
            $.post('@Url.Action("Approved")', { Id: this.value, checked: check });
         })
        var $ = layui.$, active = {
            add: function () {
                window.location.href = '@Url.Action("ApproveUser")';
            }
        }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

